using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Abp.Domain.Entities;
using Abp.Domain.Entities.Auditing;
using Abp.Runtime.Security;

namespace Abp.MultiTenancy
{
    /// <summary>
    /// Base class for tenants.
    /// 租户基类。
    /// </summary>
    [Table("AbpTenants")]
    [MultiTenancySide(MultiTenancySides.Host)]
    public abstract class AbpTenantBase : FullAuditedEntity<int>, IPassivable
    {
        /// <summary>
        /// Max length of the <see cref="TenancyName"/> property.
        /// <see cref="TenancyName"/> 属性的最大长度。
        /// </summary>
        public const int MaxTenancyNameLength = 64;

        /// <summary>
        /// Max length of the <see cref="ConnectionString"/> property.
        /// <see cref="ConnectionString"/> 属性的最大长度。
        /// </summary>
        public const int MaxConnectionStringLength = 1024;

        /// <summary>
        /// "Default".
        /// 默认租户名称。
        /// </summary>
        public const string DefaultTenantName = "Default";

        /// <summary>
        /// "^[a-zA-Z][a-zA-Z0-9_-]{1,}$".
        /// </summary>
        public const string TenancyNameRegex = "^[a-zA-Z][a-zA-Z0-9_-]{1,}$";

        /// <summary>
        /// Max length of the <see cref="Name"/> property.
        /// <see cref="Name"/> 属性的最大长度。
        /// </summary>
        public const int MaxNameLength = 128;

        /// <summary>
        /// Tenancy name. This property is the UNIQUE name of this Tenant.
        /// It can be used as subdomain name in a web application.
        /// 租户名称。这是租户的唯一名称。
        /// 它可以被用来作为 Web 应用程序中的子域名。
        /// </summary>
        [Required]
        [StringLength(MaxTenancyNameLength)]
        public virtual string TenancyName { get; set; }

        /// <summary>
        /// Display name of the Tenant.
        /// 租户的显示名称。
        /// </summary>
        [Required]
        [StringLength(MaxNameLength)]
        public virtual string Name { get; set; }

        /// <summary>
        /// ENCRYPTED connection string of the tenant database.
        /// Can be null if this tenant is stored in host database.
        /// Use <see cref="SimpleStringCipher"/> to encrypt/decrypt this.
        /// 租户数据库的加密连接字符串。
        /// 如果租户存储在宿主数据库中，可以为空引用（<c>null</c>）。
        /// 使用 <see cref="SimpleStringCipher"/> 来进行加解密。
        /// </summary>
        [StringLength(MaxConnectionStringLength)]
        public virtual string ConnectionString { get; set; }

        /// <summary>
        /// Is this tenant active?
        /// If as tenant is not active, no user of this tenant can use the application.
        /// 指示该租户是否是活动的？
        /// 如果租户不是活动的，那么这个租户中没有用户可以使用应用程序。
        /// </summary>
        public virtual bool IsActive { get; set; }
    }
}